﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace BussinessLib
{
    [Serializable]
    public class CustomPrinciple :IPrincipal
    {
        #region IPrincipal Members

        public IIdentity Identity
        {
            get
            {
                if (_wPrincipal != null)
                    return _wPrincipal.Identity;
                else
                    return _identity;
            }
        }

        public bool IsInRole(string role)
        {
            if (_wPrincipal != null)
                return _wPrincipal.IsInRole(role);
            else
            {
                //not implemented
                return true;
            }

        }


        public bool IsInRole(int rid)
        {
            if (_wPrincipal != null)
                return _wPrincipal.IsInRole(rid);
            else
            {
                //not implemented
                return false;
            }

        }


        public bool IsInRole(SecurityIdentifier si)
        {
            if (_wPrincipal != null)
                return _wPrincipal.IsInRole(si);
            else
            {
                //not implemented
                return false;
            }

        }


        public bool IsInRole(WindowsBuiltInRole wb)
        {
            if (_wPrincipal != null)
                return _wPrincipal.IsInRole(wb);
            else
            {
                //not implemented
                return false;
            }

        }


        #endregion

        WindowsPrincipal _wPrincipal = null;


        CustomIdentity _identity = null;

        public CustomPrinciple(CustomIdentity __identity)
        {
            _identity = __identity;

            if (_identity.isWindows)
                _wPrincipal = new WindowsPrincipal(_identity.windowsIdentity);
            else
                _wPrincipal = null;

            
           
        }


        private List<string> _lstRoles = new List<string>();

        public List<string> lstRoles
        {
            get { return _lstRoles; }
           
        }


       




    }
}
